package readers;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public abstract class GenericReader {
	
	protected String path;
	protected boolean skipFirstLine;

	public GenericReader(String path, boolean skipFirstLine) {
		this.path=path;
		this.skipFirstLine=skipFirstLine;
	}

	public void process() throws FileNotFoundException {	
	    
		int lineread=0;
	    try {
	     
	      BufferedReader input =  new BufferedReader(new FileReader(new File(path)));
	      try {
	        String line = null; //not declared within while loop
	       
	        while (( line = input.readLine()) != null){
	        	if (skipFirstLine && lineread++==0 )
	        			continue;
	        	processLine(line);
	        }
	      }
	      finally {
	        input.close();
	      }
	    }
	    catch (IOException ex){
	      ex.printStackTrace();
	    }		
	}

	abstract void processLine(String line);

	
	

}
